"""
这里是随机点名器后端模块
"""

import random

import Control

class Randomer(object):
    Group = {}
    
    def __init__(self,GroupAddress):
        """初始化实例 载入各个小组的组员名单

        Args:
            Groups (dict): ID: FileAddress
            eg: {A: ./A.txt,}
        """
        for id in GroupAddress.keys():
        
            with open(GroupAddress[id],'r',encoding="utf-8") as file:
                Names = file.read().splitlines()
                
            self.Group[id] = Names
        
    
    def random_list(self,groupId):
        """返回特定组打乱顺序后的列表

        Args:
            GroupId (list)
            eg: ["A","B",]
        """
        Names = []
        
        for i in groupId:
            Names += self.Group[i]
            
            #Names.append(self.Group[i])
                
        random.shuffle(Names)
        return Names
        

if __name__ == "__main__":
    """
    Address = {
        "A": "./Data/A.txt",
        "B": "./Data/B.txt",
    }"""
    #rd = Randomer(Address)
    rd = Randomer(Control.DataPath)
    
    for i in range(5):
        print(rd.random_list(['A','B']))
    

